<template>
	<uni-nav-bar title="提货单" left-icon="left" @clickLeft="navBack" :fixed="true" statusBar></uni-nav-bar>
	<view class="package" style="padding: 10rpx 20rpx 0px;">
		<uni-segmented-control
		  :current="current"
		  :values="items"
		  @clickItem="onClickItem" 
		  styleType="text"
		  activeColor="#1D92FF">
		</uni-segmented-control>
	</view>
	<!-- 列表 -->
	<scroll-view
	  scroll-y="true"
	  enable-back-to-top
	  @scrolltolower="loadMore"
	  class="scroll-box"
	  :style="{ height: pageHeight + 'px' }"
	>
	<view class="package" style="padding:20rpx 0px;margin-top: 0px;" v-for="(item,index) in orderLists" :key='item.id'>
		<view class="space-between shopTop">
			<view class="packageLsit" @click="navTo('shopp/Shopkeeper?id='+item.store_id)" >
				<image src="../../static/groupBenefits/shop.png" mode=""></image>
				<text>{{item.store_name}}</text>
				<uni-icons type="forward" size="19" color="#666"></uni-icons>
			</view>
			<view class="tit">{{item.status_text}}</view>
		</view>
		<ShopList :money="'delivery'" :shoppAll="item" @jumps="jumps" :pauth="'delivery'"></ShopList>
	</view>
	<view class="column fillings"  :style="{ height: pageHeight + 'px' }" v-if="orderLists.length<1">
	  <image :src="Empty"></image>
	  <text>暂无提货记录</text>
	</view>
	</scroll-view>
</template>

<script setup lang="ts">
	import { navBack,navTo} from '@/utils/navigator';
	import ShopList from '@c/groupBenefits/shopGrid.vue';
	import { ref,onMounted } from 'vue';
	import { onShow } from '@dcloudio/uni-app';
	import { Empty } from '@/utils/Static';
	import { toPublish } from '@mqtt';
	import { errorToast} from '@/utils/prompt';
	import { hexiaoList } from '@/gql/group';
	import { getDriverID } from '@/stores/driverID';
	const user_id = getDriverID();
	const current=ref(0) 
	const items= ['待提货', '已提货']	
	const isLoading = ref(false);
	const lastPage = ref(1);
	const currentPage = ref(1);
	const orderLists = ref([]);
	const pageHeight=ref()
	onMounted(() => {
	  uni.getSystemInfo({
	    success: function(res) {
	      pageHeight.value = (res.windowHeight - 80).toString();
	    },
	  });
	});
	onShow(()=>{
		orderLists.value=[]
		currentPage.value=1
		init()
	})
	function init() {
	  isLoading.value = true;
	  const payload = {
	    query: hexiaoList,
	    variables: {
	      page: currentPage.value,
		  user_id,
		  status:current.value
	    },
	  };
	  toPublish(
	    'ql/store/getOrderHexiaoList',
	    payload,
	    (obj: any) => {
	      const { order_hexiao_list } = obj.data;
	      isLoading.value = false;
	      orderLists.value = [...orderLists.value, ...order_hexiao_list.list];
	      lastPage.value = order_hexiao_list.lastpage;
	    },
	    () => {
	      errorToast('通讯异常');
	      isLoading.value = false;
	    },
	  );
	}
	/**
	 * 加载更多
	 */
	function loadMore() {
	  if (currentPage.value < lastPage.value) {
	    currentPage.value++;
	    init();
	  }
	}
	function onClickItem(e){
		console.log(e.currentIndex)
		current.value=e.currentIndex
		orderLists.value =[]
		currentPage.value=1;
		init();
	}
	function jumps(num){
		if(num.status=='1'){
			uni.navigateTo({
				url: '/pages/groupBenefits/upSucceeded?id='+num.num+'&storeId='+num.storeId+'&type='+num.type
			});
		}else{
			uni.navigateTo({
				url: '/pages/groupBenefits/deliveryDetail?id='+num.num+'&storeId='+num.storeId+'&type='+num.type
			});
		}
	}
</script>
<style scoped lang="less">
	@import url('../order/less/populic.less');
	.shopTop{
		width: 100%;
		box-sizing: border-box;
		padding:0px 20rpx;
	}
	.packageLsit{
			display:flex;
			align-items: center;
			image{
				width: 50rpx;
				height: 50rpx;
			}
			text{
				font-size: 30rpx;
				font-weight: 400;
				color: #181818;
				margin: 0px 10rpx;
			}
		}
		.tit{
			font-size: 28rpx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			color: #309BFF;
		}
</style>
